package jtk.project4.fleet.screen.AddPayment;

import java.awt.FlowLayout;
import java.text.SimpleDateFormat;
import java.util.List;


import jtk.project4.fleet.action.CancelAction;
import jtk.project4.fleet.action.SubmitAction;
import jtk.project4.fleet.domain.AddPayment;
import jtk.project4.fleet.event.AddPaymentEvent;
import jtk.project4.fleet.field.PaymentMethodField;

//import com.sun.corba.se.spi.orbutil.fsm.Action;

import nl.coderight.jazz.form.FormField;
import nl.coderight.jazz.form.FormHeader;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.CalendarControl;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.field.NumberField;
import nl.coderight.jazz.form.field.SelectField;
import nl.coderight.jazz.form.field.TextField;
import nl.coderight.jazz.form.field.button.PushButton;
import nl.coderight.jazz.form.FormLayout;
import nl.coderight.jazz.form.FormHeader;


public class AddPaymentView extends FormView {
	//public AddPaymentView() {
		//super(elem);
// TODO Auto-generated constructor stub
	//}

	private FormHeader formHeader;
	private PushButton submitButton;
	private PushButton cancelButton;
	//private Action submitAction;
	//private Action cancelAction;
	
	private SelectField m1Field;
	private CalendarControl m2Field;
	private NumberField n1Field;
	
	
	protected void init() {
		createFields();
		createLayout();		
	}
	//}
	

		

	private GroupControl createFields(){
		GroupControl fields = new GroupControl();
		
		submitButton = new PushButton("submitAction");
		cancelButton = new PushButton("cancelAction");
		
		m1Field = new SelectField ("invoice", "20");
		
		m2Field = new CalendarControl("date", 20);
		
		n1Field = new NumberField("amount", 20);

		m2Field.setFormat(new SimpleDateFormat());
		m2Field.showYearSpinner(true);
		m2Field.setPreferredSize(n1Field.getPreferredSize());
		
		fields.setLayout(new FormLayout())
		.addLabel("Invoice #;")
		.addField(m1Field)
		.addRow()
		.addLabel("Amount Received: ") .addField(n1Field)
		.addRow()
		.addLabel("Date Received") .addField(m2Field)
		.addRow();
		return fields;
		
	}
	
	private void createLayout() {
		//setHeader(createHeader());
		addField(createForm());
	}
	

	private FormHeader createHeader() {
		formHeader = new FormHeader();
		formHeader.setTitle("addPayment.header.form");
		return formHeader;
	}
	
	private GroupControl createForm() {
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())
		.addField(createFields())
		//.addLabel("Payment Method: ") .addField(n1Field)
		//.addRow();
		//.addField(new NumberField("Amount Received: ", 20))
		.addRow()
		
		.addField(new PaymentMethodField ("Payment Method"))
		.addRow()
		.addField(createButtons());
		return form;
	}
	
	private GroupControl createButtons() {
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(submitButton);
		buttons.addField(cancelButton);
		return buttons;
	}
	
}
